﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Meraz.Core.Data;
using System.Runtime.Serialization;

namespace Meraz.Core.Model
{
    [PetaPoco.TableName("facebookpost")]
    [PetaPoco.PrimaryKey("ID,TopicID,BoardID", autoIncrement = false)]
    [PetaPoco.ExplicitColumns]
    [Serializable]
    [DataContract]
    public class FacebookTopicPost
    {
        public FacebookTopicPost() { 
            Links = new List<FacebookTopicPostLink>();
            Genre = string.Empty;
            Poster = string.Empty;
            Status = string.Empty;
            Subject = string.Empty;
            Text = string.Empty;
        }
        [PetaPoco.Column]
        [DataMember]
        public int ID { get; set; }

        public string IDStr { get { return ID.ToString(); } set { int temp; if (int.TryParse(value, out temp)) ID = temp; } }

        [PetaPoco.Column]
        [DataMember]
        public int TopicID { get; set; }

        public string TopicIDStr { get { return TopicID.ToString(); } set { int temp; if (int.TryParse(value, out temp)) TopicID = temp; } }

        [PetaPoco.Column]
        [DataMember]
        public long BoardID { get; set; }

        public string BoardIDStr { get { return BoardID.ToString(); } set { long temp; if (long.TryParse(value, out temp)) BoardID = temp; } }
        [PetaPoco.Column]
        [DataMember]
        public string Text { get; set; }
        [DataMember]
        public List<FacebookTopicPostLink> Links { get; set; }
        public DateTime CreatedDate { get; set; }
        [PetaPoco.Column]
        [DataMember]
        public string Poster { get; set; }
        [PetaPoco.Column]
        [DataMember]
        public string Genre { get; set; }
        [PetaPoco.Column]
        [DataMember]
        public string Subject { get; set; }

        [PetaPoco.Column]
        [DataMember]
        public string Status { get; set; }

        [DataMember]
        public string CreatedDateString
        {
            get { return CreatedDate.ToString(); }
            set
            {
                DateTime temp;
                if (DateTime.TryParse(value, out temp)) CreatedDate = temp;
            }
        }

        [PetaPoco.Column]
        public long CreatedDateTicks
        {
            get { return CreatedDate.Ticks; }
            set { CreatedDate = new DateTime(value); }
        }
        [PetaPoco.Column]
        [DataMember]
        public int WordCount { get; set; }

        public bool HasLinks
        {
            get { return Links.Count > 0; }
        }
    }
}
